package cn.easybuy.service;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.easybuy.biz.Easybuy_UserBiz;
import cn.easybuy.biz.Impl.Easybuy_UserBizImpl;
import cn.easybuy.entity.Easybuy_User;

public class Easybuy_UserService extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		String passwordw = request.getParameter("password1");
		String emli = request.getParameter("emli");
		String shouji = request.getParameter("shouji");

		Easybuy_UserBiz easybuy_UserBiz = new Easybuy_UserBizImpl();
		Easybuy_User easybuy_User = new Easybuy_User();
		easybuy_User.setLoginName(name);
		easybuy_User.setUserName("张三");
		easybuy_User.setPassword(password);
		easybuy_User.setSex(1);
		easybuy_User.setIdentityCode("320821199309222113");
		easybuy_User.setEmail(emli);
		easybuy_User.setMobile(shouji);
		easybuy_User.setType(1);
		int a = easybuy_UserBiz.adduser(easybuy_User);
		if(a>0){
			HttpSession  session=request.getSession();
			session.setAttribute("USER", easybuy_User);
		request.getRequestDispatcher("../Login.jsp").forward(request, response);
		}else{
			request.getRequestDispatcher("../Regist.jsp").forward(request, response);
		}
	}
}
